package pri.zxx.webdemo.interceptor;

import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpRequest;
import org.apache.http.HttpRequestInterceptor;
import org.apache.http.protocol.HttpContext;
import org.springframework.stereotype.Component;
import pri.zxx.webdemo.utils.MDCUtil;
import pri.zxx.webdemo.utils.TokenHolder;

/**
 * 为HttpClient 透传requestId
 *
 * @author wangn <15124178@qq.com> 2020/9/21
 */
@Slf4j
@Component
public class HttpClientInterceptor implements HttpRequestInterceptor, CustomHandleInterceptor {
    @Override
    public void process(HttpRequest httpRequest, HttpContext httpContext) {
        String s = MDCUtil.initRequestId();
        httpRequest.addHeader(MDCUtil.REQUEST_ID, s);
        httpRequest.addHeader("token", TokenHolder.get());
    }
}
